server = {
    _svr = nil,
    _conn = nil,
    _port,
    _router = {}
}

function server:getPath(header)
    local _, _, method, path = string.find(header, '([A-Z]+) (.+) HTTP')
    return path or nil
end

function server:listen(port)
    self._port = port
    self._svr = net.createServer(net.TCP)
    self._svr:listen(self._port, function(conn)
        conn:on('receive', function(skt, header)
            local path = self.getPath(header)
            for i=1, #self._router do
                if string.find(path, '^'.self._router[i].path.'$') then
                    self._router[i].func(skt, path)
                    break
                end
            end
            collectgarbage()
        end)
    end)
end

function server:bind(path, func)
    table.insert(self._router, #self._router, {path=path, func=func})
end